<style>
    .form-copy {
        margin-right: 5px;
        border-radius: 0;
        box-shadow: none;
        padding: 4px 12px 7px 12px;
        font-size: 14px;
        line-height: 1.42857143;
        color: #555;
        border: 1px solid #ccc;
        transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
    }
    .select2 {
        margin-right: 5px
    }
</style>
<div class="btn-group" style="margin-right: 10px">
    <form action="{{ $action }}" pjax-container method="get">
        <input type="text" class="form-copy" style=" width:500px;" name="amazon_order_id" value="{{ $filtersBlade['amazon_order_id'] }}" placeholder="多订单号查询用英文逗号隔开(最多可同时查询10个)" required>
        <button class="btn btn-sm btn-info submit"><i class="fa fa-search"></i>&nbsp;&nbsp;{{ trans('admin.search') }}</button>
        <a style="margin-left: 10px;" href="{{ $action }}" class="btn btn-sm btn-default"><i class="fa fa-undo"></i>&nbsp;&nbsp;{{ trans('admin.reset') }}</a>
    </form>
{{--    <div>--}}
{{--        <select id="area_id">--}}
{{--            {{ getOptions(\App\Models\Basics\AmazonArea::options()) }}--}}
{{--        </select>--}}
{{--        <button class="btn btn-sm btn-twitter sync"><i class="fa fa-retweet"></i>&nbsp;&nbsp;<span id="loading">同步</span></button>--}}
{{--        <span style="color: blue;">(可以给要同步的订单号指定同步条件：站点)</span>--}}
{{--    </div>--}}
</div>

<script language="JavaScript" type="text/javascript">
    $(function () {
        $('#area_id').select2({placeholder: '站点', allowClear: true, width: '100px'});
        $('.sync').on('click', function(e) {
            e.preventDefault();
            var amazonOrderId = $('input[name="amazon_order_id"]').val();
            if(amazonOrderId.trim() == ''){
                swal('订单号不能为空', '', 'error');
                return false;
            }
            var areaId = $('#area_id').val();
            $.ajax({
                method: 'post',
                url: '/xqc/order/amazon-ajax',
                data: {
                    _token:"{{ csrf_token() }}",
                    action:'syncOrder',
                    param:{'amazonOrderId':amazonOrderId,'areaId':areaId}
                },
                beforeSend: function(){
                    $('#loading').text('同步中，请耐心等待。');
                    $('.sync').attr('disabled',true);
                },
                success: function (data) {
                    $('#loading').text('同步');
                    $('.sync').removeAttr('disabled');
                    $.pjax.reload('#pjax-container');
                    if (typeof data === 'object') {
                        if (data.status) {
                            toastr.success('提交成功 !');
                        } else {
                            swal(data.message, '', 'error');
                        }
                    }
                }
            });
        });
    });
</script>
